// ==UserScript==
// @name         替换微博跳转链接
// @namespace    http://tampermonkey.net/
// @version      0.0.2-2024-11-14
// @description  替换微博中的重定向链接，直接跳转到目标地址
// @author       AgMonk
// @match        https://weibo.com/*
// @icon         https://weibo.com/favicon.ico
// @grant        none
// @homepage     https://gitee.com/AgMonk/tampermonkey-script
// @downloadURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/%E5%BE%AE%E5%8D%9A/replace-redirect-link.user.js
// @updateURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/%E5%BE%AE%E5%8D%9A/replace-redirect-link.user.js
// ==/UserScript==

(function() {
    'use strict';

    setInterval(()=>{
        // 获取需要修改的链接标签
        const links = [...document.getElementsByTagName('a')].filter(i=>i.href.startsWith('https://weibo.cn/sinaurl'))
        const count = links.length
        if (count==0) return
        console.log(`替换 ${count} 个跳转链接`)

        links.forEach(link=>{
            link.href = new URL(link.href).searchParams.get('u')
        })
    },1000)
})();